/// todo实体
class TodoEntity {
  late String content;
  late int state;
  int? index;

  TodoEntity({required this.content, required this.state, this.index});

  TodoEntity.fromJson(dynamic json) {
    content = json['content'] ?? '';
    state = json['state'] ?? TodoStateConst.unDone;
    index = json['index'];
  }

  Map<String, dynamic> toJson() {
    final map = <String, dynamic>{};
    map['content'] = content;
    map['state'] = state;
    map['index'] = index;
    return map;
  }

  @override
  bool operator ==(Object other) => identical(this, other) || other is TodoEntity && runtimeType == other.runtimeType && index == other.index;

  @override
  int get hashCode => index.hashCode;

  bool isDone() {
    return state == TodoStateConst.done;
  }

  @override
  String toString() {
    return 'TodoEntity{content: $content, state: $state, index: $index}';
  }
}

class TodoStateConst {
  /// 未完成
  static final int unDone = 0;

  /// 完成
  static final int done = 1;
}
